package com.librarysys.service.impl;

import com.librarysys.common.Result;
import com.librarysys.dao.ReaderMapper;
import com.librarysys.dao.ReadertypeMapper;
import com.librarysys.entity.Reader;
import com.librarysys.entity.Readertype;
import com.librarysys.service.IReaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yuhui on 2017/7/12.
 */
@Service("iReaderService")
public class ReaderServiceImpl implements IReaderService {

    @Autowired
    private ReadertypeMapper readertypeMapper;

    @Autowired
    private ReaderMapper readerMapper;

    @Override
    public Result listReaderType() {
        List<Readertype> readertypes = readertypeMapper.selectAll();
        return Result.createBySuccess("查询成功",readertypes);
    }

    public Result addReaderType(Readertype readertype){
        int insert = readertypeMapper.insert(readertype);
        if(insert>0){
            return Result.createBySuccess("添加成功");
        }else{
            return Result.createByError("添加失败");
        }
    }

    public Result delReaderType(Integer id){
        int i = readertypeMapper.deleteByPrimaryKey(id);
        if(i>0){
            return Result.createBySuccess("删除成功");
        }else{
            return Result.createByError("删除失败");
        }
    }

    @Override
    public Result listReader() {
        List<Reader> readers = readerMapper.selectAll();
        return Result.createBySuccess("查询成功",readers);
    }
    public Result addReader(Reader reader){
        int insert = readerMapper.insert(reader);
        if(insert>0){
            return Result.createBySuccess("添加成功");
        }else{
            return Result.createByError("添加失败");
        }
    }

    public Result delReader(Integer id){
        int i = readerMapper.deleteByPrimaryKey(id);
        if(i>0){
            return Result.createBySuccess("删除成功");
        }else{
            return Result.createByError("删除失败");
        }
    }
}
